Read user info from csv


In [17]:
import csv

In [23]:
import csv
users = []
f = open('data.csv', 'r', encoding='utf-8')
rdr = csv.reader(f)
for line in rdr:
    users.append({
        "name": line[0],
        "id": line[1],
        "repo": line[2],
    })
f.close()
users


Out[23]:
[{'id': 'honux77', 'name': '정호영', 'repo': 'ml-squad'}]

Read github repo


In [1]:
import requests

In [30]:
def countCommits(commits):
    count = 0;
    for commit in commits:
        count += 1
    return count
def getLastDate(commits):
    return commits[0]['commit']['author']['date']

In [42]:
def readGithub(user):
    cmd = "/repos/" + user["id"] + "/ml-squad/commits"
    res = requests.get(url + cmd)
    if res.status_code == 200:
        commits = res.json()
        user['count'] = countCommits(commits)
        user['last_commit'] = getLastDate(commits)
    else:
        user['count'] = -1
        user['last_commit'] = "Some Error"

In [43]:
for user in users:
    readGithub(user)
users


Out[43]:
[{'count': 2,
  'id': 'honux77',
  'last_commit': '2017-12-18T09:44:36Z',
  'name': '정호영',
  'repo': 'ml-squad'}]

In [40]:
cmd = "/repos/" + "honux77" + "/ml-squad/commits"
res = requests.get(url + cmd)